import 'dart:ui';
import 'package:factoryside/api/api.dart';
import 'package:factoryside/utils/ColorsUtils.dart';
import 'package:factoryside/utils/request_util.dart';
import 'package:factoryside/utils/utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


///修改服务类型

class ChangeServiceTypePage extends StatefulWidget {
  int serviceType;//服务类型(1维修2安装3质保4.清洁5.用户送修)
  String guarantee;//Y保内 N保外
  int orderId;


  ChangeServiceTypePage(this.serviceType, this.guarantee, this.orderId);

  @override
  State<StatefulWidget> createState() {
    return _ChangeServiceTypeState();
  }
}

class _ChangeServiceTypeState extends State<ChangeServiceTypePage>
    with AutomaticKeepAliveClientMixin {

  bool _hasSelected=false;
  bool _noSelected=false;
  bool _songSelected=false;

  bool _honaiSelected=false;
  bool _warrantySelected=false;

  @override
  void initState() {
    super.initState();
    setState(() {
      if(widget.serviceType==1){
        _hasSelected=false;
        _noSelected=true;
        _songSelected=false;
      }else if(widget.serviceType==2){
        _hasSelected=true;
        _noSelected=false;
        _songSelected=false;
      }else if(widget.serviceType==5){
        _hasSelected=false;
        _noSelected=false;
        _songSelected=true;
      }
      if(widget.guarantee=='Y'){
        _honaiSelected=true;
        _warrantySelected=false;
      }else{
        _honaiSelected=false;
        _warrantySelected=true;
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context); //必须实现 不然 在push过后页面会刷新
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('修改服务类型'),
      ),
      body: SafeArea(
        bottom: false,
        child: Container(
        color: ColorsUtil.hexToColor('#EFEFEF'),
        child: Column(children: [
          Expanded(
            child: ListView(
              children: [
                Container(
                  margin: EdgeInsets.only(top:10),
                  child: Column(
                    children: [
                      Container(
                        color: Colors.white,
                        padding: EdgeInsets.all(10),
                        child: Row(
                          children: [
                            Text('*服务类型：'),
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  // 复选框
                                  GestureDetector(
                                    behavior: HitTestBehavior.opaque,
                                    child: Row(
                                      children: [
                                        Container(
                                          padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5),
                                          child: Image.asset(
                                            _hasSelected
                                                ? 'assets/checked.png'
                                                : 'assets/unchecked.png',
                                            width: 15,
                                            height: 15,
                                          ),
                                        ),
                                        Text('安装',
                                            textAlign: TextAlign.end,
                                            style: TextStyle(

                                                color: Colors.black)),
                                      ],
                                    ),
                                    onTap: () {
                                      setState(() {
                                        _hasSelected = true;
                                        _noSelected = false;
                                        _songSelected = false;
                                        widget.serviceType=2;
                                      });
                                    },
                                  ),
                                  GestureDetector(
                                    behavior: HitTestBehavior.opaque,
                                    child: Row(
                                      children: [
                                        Container(
                                          padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5),
                                          child: Image.asset(
                                            _noSelected
                                                ? 'assets/checked.png'
                                                : 'assets/unchecked.png',
                                            width: 15,
                                            height: 15,
                                          ),
                                        ),
                                        Text('维修',
                                            textAlign: TextAlign.end,
                                            style: TextStyle(
                                                color: Colors.black)),
                                      ],
                                    ),
                                    onTap: () {
                                      setState(() {
                                        _hasSelected = false;
                                        _noSelected = true;
                                        _songSelected = false;
                                        widget.serviceType=1;
                                      });
                                    },
                                  ),
                                  Expanded(
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      child: Row(
                                        children: [
                                          Container(
                                            padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5),
                                            child: Image.asset(
                                              _songSelected
                                                  ? 'assets/checked.png'
                                                  : 'assets/unchecked.png',
                                              width: 15,
                                              height: 15,
                                            ),
                                          ),
                                          Expanded(
                                            child: Text('用户送修',
                                                style: TextStyle(
                                                    color: Colors.black)),
                                          ),
                                        ],
                                      ),
                                      onTap: () {
                                        setState(() {
                                          _hasSelected = false;
                                          _noSelected = false;
                                          _songSelected = true;
                                          widget.serviceType=5;
                                        });
                                      },
                                    ),
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                      ),
                      Divider(
                        height: 1,
                      ),
                      Container(
                        color: Colors.white,
                        padding: EdgeInsets.all(10),
                        child: Row(
                          children: [
                            Text('*售后类型：'),
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  // 复选框
                                  GestureDetector(
                                    behavior: HitTestBehavior.opaque,
                                    child: Row(
                                      children: [
                                        Container(
                                          padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5),
                                          child: Image.asset(
                                            _honaiSelected
                                                ? 'assets/checked.png'
                                                : 'assets/unchecked.png',
                                            width: 15,
                                            height: 15,
                                          ),
                                        ),
                                        Text('保内',
                                            textAlign: TextAlign.end,
                                            style: TextStyle(

                                                color: Colors.black)),
                                      ],
                                    ),
                                    onTap: () {
                                      setState(() {
                                        _honaiSelected = true;
                                        _warrantySelected = false;
                                        widget.guarantee='Y';
                                      });
                                    },
                                  ),
                                  GestureDetector(
                                    behavior: HitTestBehavior.opaque,
                                    child: Row(
                                      children: [
                                        Container(
                                          padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5),
                                          child: Image.asset(
                                            _warrantySelected
                                                ? 'assets/checked.png'
                                                : 'assets/unchecked.png',
                                            width: 15,
                                            height: 15,
                                          ),
                                        ),
                                        Text('保外',
                                            textAlign: TextAlign.end,
                                            style: TextStyle(

                                                color: Colors.black)),
                                      ],
                                    ),
                                    onTap: () {
                                      setState(() {
                                        _honaiSelected = false;
                                        _warrantySelected = true;
                                        widget.guarantee='N';
                                      });
                                    },
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
              color: Colors.white,
              padding: EdgeInsets.fromLTRB(0,5,20,5),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  ElevatedButton(onPressed: () {
                    RequestUtil.post(Api.updateServiceType, {
                      'TypeID':widget.serviceType,
                      'Guarantee':widget.guarantee,
                      'OrderID':widget.orderId
                    }).then((value) {
                        if(value['Data']['code']==0){
                          Navigator.pop(context,true);
                        }else{
                          showToast(value['Data']['msg']);
                        }
                    });
                  }, child: Text('提交')),
                ],
              )),
        ]),
      ),),
    );
  }

}
